<template>
    <div>
        <h2>病房显示列表</h2>
        <input type="button" value="添加病房" @click="addbf">
        <input type="button" value="添加科室" @click="addks">
        <br>
        科室：<select v-model="obj.kname" name="" id="">
                            <option value="">请选择</option>
                            <option value="内科">内科</option>
                            <option value="外科">外科</option>
                            <option value="心脑科">心脑科</option>
                        </select>
        病房号：<input v-model="obj.name" type="text">
        <input type="button" value="查询" @click="cha">
        <table class="table">
            <thead>
                <tr>
                    <td>病房号</td>
                    <td>所属科室</td>
                    <td>床位数</td>
                    <td>状态</td>
                    <td>空床位</td>
                    <td>创建时间</td>
                    <td>更新时间</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="i in data">
                    <td>{{i.name}}</td>
                    <td>{{i.kname}}</td>
                    <td>{{i.num}}</td>
                    <td>{{i.state?"启用":"维修"}}</td>
                    <td>{{i.knum}}</td>
                    <td>{{i.startdate.substring(0,10)}}</td>
                    <td>{{i.enddate.substring(0,10)}}</td>
                    <td>
                        <input v-if="i.state" type="button" value="维修" @click="upstate(i.id)">
                    </td>
                </tr>
            </tbody>
        </table>
        <input type="button" value="首页" @click="getpage(1)">
        <input type="button" value="上一页" @click="getpage(2)">
        <input type="button" value="下一页" @click="getpage(3)">
        <input type="button" value="尾页" @click="getpage(4)">
        共{{ obj.pcount }}/{{ obj.index }}页，共{{ obj.count }}条，每页{{ obj.size }}条
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
const router=useRouter();

onMounted(()=>{
    show();
})
const data=ref([{
      "id": 0,
      "name": "string",
      "kname": "string",
      "num": 0,
      "state": true,
      "knum": 0,
      "startdate": "2025-02-18T08:27:30.478Z",
      "enddate": "2025-02-18T08:27:30.478Z"
    }])
const obj=ref({
    index:1,
    size:2,
    kname:'',
    name:'',
    count:0,
    pcount:0
})
const show=()=>{
    axios.get('https://localhost:7260/api/BingFang/ShowBingFang',{params:obj.value}).then(res=>{
        data.value=res.data.data;
        obj.value.count=res.data.count;
        obj.value.pcount=Math.ceil(obj.value.count/obj.value.size);
    })
}
const getpage=(i:any)=>{
    if(i==1){
        obj.value.index=1;
        show();
    }
    if(i==2&&obj.value.index>1){
        obj.value.index-=1;
        show();
    }
    if(i==3&&obj.value.index<obj.value.pcount){
        obj.value.index+=1;
        show();
    }
    if(i==4){
        obj.value.index=obj.value.pcount;
        show();
    }
}
const upstate=(id:any)=>{
    if(confirm('确认维修吗？'))
    axios.get('https://localhost:7260/api/BingFang/UpdateBingFangState',{params:{id:id}}).then(res=>{
        if(res.data>0){
            alert('修改成功');
            show();
        }
    })
}
const cha=()=>{
    if(confirm('确认查询吗？'))
    obj.value.index=1;
    show();
}
const addbf=()=>{
    router.push('/addbf');
}
const addks=()=>{
    router.push('/addks');
}
</script>

<style scoped>

</style>